package com.huatai.exchange.bootup.controller;

import com.faneui.bootup.controller.AbstractRestController;
import com.faneui.common.exception.BusinessException;
import com.faneui.common.utils.BeanMapper;
import com.faneui.common.utils.ListUtils;
import com.huatai.exchange.dal.model.ExcAutoSendCustMailTask;
import com.huatai.exchange.facade.AutoSendCustMailTaskController;
import com.huatai.exchange.facade.bean.AutoSendCustMailTaskVo;
import com.huatai.exchange.facade.bean.QueryAutoSendCustMailTaskVoListResp;
import com.huatai.exchange.service.ExcAutoSendCustMailTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "task")
@Api("自动任务发送配置信息")
public class AutoSendCustMailTaskControllerImpl extends AbstractRestController implements AutoSendCustMailTaskController {

    @Autowired
    private ExcAutoSendCustMailTaskService excAutoSendCustMailTaskService ;
    
    @ApiOperation("查询配置信息")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public QueryAutoSendCustMailTaskVoListResp queryAutoSendCustMailTaskVoList(@ModelAttribute AutoSendCustMailTaskVo autoSendCustMailTaskVo) throws BusinessException {
        QueryAutoSendCustMailTaskVoListResp resp = new QueryAutoSendCustMailTaskVoListResp();
        try {
            ExcAutoSendCustMailTask info = BeanMapper.map(autoSendCustMailTaskVo,ExcAutoSendCustMailTask.class) ;
            List<ExcAutoSendCustMailTask> infos = excAutoSendCustMailTaskService.queryExcAutoSendCustMailTaskList(info) ;
            if(ListUtils.isNotEmpty(infos)) {
                List<AutoSendCustMailTaskVo> vos = BeanMapper.mapList(infos,AutoSendCustMailTaskVo.class) ;
                resp.setAutoSendCustMailTaskVos(vos);
            }
        }catch (Exception ex) {
            resp.setSuccess(false);
            resp.setMsg(ex.getMessage());
        }
        return resp;
    }
}
